#include <linux/sched.h>
#include <linux/kernel.h>

int ROOT_DEV = 0;

struct d_super_block ds;

static struct d_super_block *read_super(int dev)
{
    struct d_super_block *s = &ds;
    struct buffer_head *bh, *bh1;
    
    bh = bread(dev, 1);
    if (!bh)
        return NULL;
    bh1 = bread(dev, 2);
    if (!bh1)
        return NULL;
    printk("bh: %x, bh1: %x\n", bh, bh1);
    __asm__("cld"::);   // 不加这句，结构体赋值会出错
    *s = *((struct d_super_block *) bh->b_data);
    if (s->s_magic != SUPER_MAGIC)
        return NULL;
    return s;
}

void mount_root(void)
{
    struct d_super_block *p;
    
    p = read_super(ROOT_DEV);
    if (!p)
        panic("Unable to read super block");
    printk("s_ninodes:       %x\r\n", p->s_ninodes);
    printk("s_nzones:        %x\r\n", p->s_nzones);
    printk("s_imap_blocks:   %x\r\n", p->s_imap_blocks);
    printk("s_zmap_blocks:   %x\r\n", p->s_zmap_blocks);
    printk("s_firstdatazone: %x\r\n", p->s_firstdatazone);
    printk("s_log_zone_size: %x\r\n", p->s_log_zone_size);
    printk("s_max_size:      %x\r\n", p->s_max_size);
    printk("s_magic:         %x\r\n", p->s_magic);
}